﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Zatify.Domain.Data
{
    public partial class Category
    {
        public IEnumerable<Category> ChildCategories
        {
            get
            {
                Zatify.Domain.Concrete.ZatifyRepository _db = new Zatify.Domain.Concrete.ZatifyRepository();
                return _db.Categories.Where(x => x.ParentId == this.CategoryId);
            }
        }

        public Category ParentCategory
        {
            get
            {
                Zatify.Domain.Concrete.ZatifyRepository _db = new Zatify.Domain.Concrete.ZatifyRepository();
                return _db.Categories.FirstOrDefault(x => x.CategoryId == this.ParentId);
            }
        }

        public bool IsSelectable()
        {
            //var categoryName = "Personal";

            //return !(String.Equals(this.CategoryName, categoryName) || (this.ParentCategory != null && String.Equals(this.ParentCategory.CategoryName, categoryName)));

            return  !(this.ChildCategories.Count() > 0);
        }

        public bool IsSingleSelection
        {
            get
            {
                //return (this.ParentCategory != null && (this.IsSelectable() && !this.ParentCategory.IsSelectable()));
                return this.IsSingularSelection.Value;
            }
        }
    }
}
